package com.wanjia.seal.manager.controller;

import com.alibaba.fastjson.JSONObject;
import com.wanjia.seal.manager.annotation.LoginToken;
import com.wanjia.seal.manager.entity.TradeResultLog;
import com.wanjia.seal.manager.entity.TradeResultLogVO;
import com.wanjia.seal.manager.mapper.TradeResultLogMapper;
import com.wanjia.seal.manager.utils.JsonResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@Controller
@RequestMapping("/api")
@Api(tags = "流水结果日志表查询")
public class TradeResultLogsController extends BaseController{
    @Autowired
    TradeResultLogMapper tradeResultLogMapper;

    @ResponseBody
    @PostMapping("/getTraderesultlog")
    @LoginToken
    public JsonResult<Object> findAlltradeResultLog(@RequestBody TradeResultLog tradeResultLog, String startTime, String endTime, Integer pageNum, Integer pageSize)  {
        String Account = tradeResultLog.getAccount();
        String Bank = tradeResultLog.getBank();
        String OperatorID = tradeResultLog.getOperatorID();
        String CheckID = tradeResultLog.getCheckID();
        String CheckType = tradeResultLog.getCheckType();
        String Result = tradeResultLog.getResult();
        String SealResult = tradeResultLog.getSealResult();
        String TradeType = tradeResultLog.getTradeType();
        List<String> list = Arrays.asList(Bank.split(","));
        if (startTime==null){
           startTime ="1988-01-01";
       }
       if (endTime==null){
           endTime="2099-01-01";
       }

        if (pageNum != null){
            List<TradeResultLogVO> result = tradeResultLogMapper.findByTradeResultLog(Account,list,OperatorID,startTime,endTime,CheckID,CheckType,Result,SealResult,TradeType,pageNum,pageSize);
            List<TradeResultLogVO> result2 = tradeResultLogMapper.findByTradeResultLogs(Account,list,OperatorID,startTime,endTime,CheckID,CheckType,Result,SealResult,TradeType);
            int size = result2.size();
            JSONObject jsonObject=new JSONObject();
            jsonObject.put("total",size);
            jsonObject.put("TradeResultLog",result);
            return new JsonResult<>(OK,jsonObject);
        }else {
            List<TradeResultLogVO> result = tradeResultLogMapper.findByTradeResultLogs(Account,list,OperatorID,startTime,endTime,CheckID,CheckType,Result,SealResult,TradeType);
            int size = result.size();
            JSONObject jsonObject=new JSONObject();
            jsonObject.put("total",size);
            jsonObject.put("TradeResultLog",result);
            return new JsonResult<>(OK,jsonObject);
        }

    }
}
